<template>
  <p style="line-height: 3.125rem; font-size: 1rem; font-weight: bold;" class="main_text">
    账户提现
  </p>
  <div class="main">
    <!-- ############################################## 表单 ############################################## -->
    <div class="content">
      <el-form :model="formData" label-width="6.25rem" label-position="left">
        <el-form-item label="账户类型：" style="width:300px;">
          <el-text>资金账户</el-text>
          <!-- <el-select v-model="formData.name" placeholder="账户类型" style="width:50%">
            <el-option label="资金账户Ⅰ" value="1" />
            <el-option label="资金账户Ⅱ" value="0" />
          </el-select> -->
        </el-form-item>
        <el-form-item label="账户余额：" style="width:300px;">
          <p><span style="color: red;">{{ balance }}</span>&nbsp;元</p>
        </el-form-item>
        <el-form-item label="提现金额：" style="width:300px;" class="df aic">
          <el-input v-model="formData.amount" style="width:50%" type="number" />
          <p class="allWithdraw ml10" @click="fullWithdrawal">全部提现</p>
        </el-form-item>
        <el-form-item label="提现卡：" style="width:400px;">
          <el-text>开户行：{{ formData.cardType }}</el-text>
          <el-input v-model="formData.bankCardNo" class="mt10" />
        </el-form-item>
        <el-form-item label="到账类型：" style="width:300px;" class="df aic">
          <el-checkbox v-model="formData.type" label="" size="large" />
          <p class="checkTips">实时到账</p>
        </el-form-item>
        <el-form-item label="">
          <el-button type="primary" @click="withdrawalSubmit">提现</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
  <el-dialog v-model="outerVisible" align-center width="40%">
    <template #header>
      <div class="df aic">
        <el-icon style="color: #fff;" size="20">
          <Warning />
        </el-icon>&nbsp;
        <p style="color: #fff;">提示</p>
      </div>
    </template>
    <div>
      <span>你尚未进行支付认证，暂无法充值，</span>
      <span style="color: #2e5882;cursor: pointer;user-select: none;" @click="approve">点击此处立即前往认证</span>
    </div>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="outerVisible = false">取消</el-button>
        <el-button type="primary" @click="approve">前往认证</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { ElMessage } from "element-plus";
import { formatTime } from "@/filters/index";
import { Warning } from "@element-plus/icons-vue";
import { RequestCompaniesGetBalance, RequestCompaniesWithdraw, RequestCompaniesGetBankCardInfo } from "@/api/path/index.js";
import { ref } from "vue";
import { useRouter } from "vue-router";
const router = useRouter();
const formData = ref<any>({
  name: "你好",
  type: true,
  bankCardNo: '',
  cardType: '',
  amount: '',
});
const balance = ref<any>('0')
const outerVisible = ref<any>(false)
const getData = () => {
  RequestCompaniesGetBalance().then((res: any) => {
    if (res.success == true) {
      console.log('asdadsas====================>>>>>>>>>>>>>>>>>', res.resultObj.result.accountInfoList);
      res.resultObj.result.accountInfoList.forEach((item: any) => {
        if (item.accountType == 'FUND_ACCOUNT') {
          balance.value = item.balance
        }
      })
    } else {
      outerVisible.value = true
    }
  })
}
const approve = () => {
  router.push({ path: '/System/System_payWarrant' })
}
const getCardData = () => {
  RequestCompaniesGetBankCardInfo().then((res: any) => {
    console.log(res)
    if (res.success == true) {
      formData.value.bankCardNo = res.resultObj.accountNo
      formData.value.cardType = res.resultObj.openBankName
    } else {
      ElMessage.error(res.msg)
    }
  })
}
getCardData()
getData()
const fullWithdrawal = () => {
  formData.value.amount = balance.value
}
const withdrawalSubmit = () => {
  if (formData.value.amount != '') {
    RequestCompaniesWithdraw({
      amount: formData.value.amount,
      receiveType: 'real_time',
      bankCardNo: formData.value.bankCardNo,
    }).then((res: any) => {
      console.log(res)
      if (res.success == true) {
        if (res.resultObj.result.returnCode == 'UA00000') {
          ElMessage.success(res.resultObj.result.returnMsg)
          getData()
        } else {
          ElMessage.error(res.resultObj.result.returnMsg)
        }
      } else {
        ElMessage.error(res.msg)
      }
    })
  } else {
    ElMessage.error('请输入提现金额')
  }
}
</script>

<style scoped lang="scss">
.main {
  width: 100%;

  .top {
    width: 100%;
    background-color: #fff;
  }

  .content {
    padding: 40px;
    width: 100%;
    background-color: #fff;
  }
}

.checkTips {
  color: #606266;
  user-select: none;
  cursor: pointer;
}

.allWithdraw {
  color: #116cf8;
  user-select: none;
  cursor: pointer;
}

.tips {
  font-size: 14px;
  color: #333;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  user-select: none;
  cursor: pointer;

  .hit {
    color: #116cf8;
  }
}

.icon_i {
  position: absolute;
  top: 0;
  bottom: 0;
  left: -6.875rem;
  right: 0;
  margin: auto 0;
}

.downLoad {
  line-height: 1rem;
  margin-left: 0.625rem;
  color: #116cf8;
}

.el-select {
  width: 100%;
}

.el-input-number {
  width: 100%;
}

.drawer_top {
  width: 100%;
  background-color: #fff;
  border-radius: 0.5rem;
}

/* 弹出框样式 */
::v-deep .el-overlay {
  .el-dialog__header {
    background-color: #116cf8;
    margin-right: 0;

    .el-icon svg {
      color: #fff;
    }
  }

  .el-dialog__title {
    color: #fff;
  }

  .el-button {
    .el-icon svg {
      color: #116cf8;
    }
  }
}

::v-deep.el-checkbox.el-checkbox--large .el-checkbox__inner {
  border-radius: 50%;
}
</style>